package com.gobang;

import com.gobang.modules.message.MsgDispatcher;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;

@Slf4j
@SpringBootApplication
@MapperScan("com.gobang.mapper")
public class GobangServerApplication  implements CommandLineRunner, ApplicationListener<ContextClosedEvent> {

    @Autowired
    private MsgDispatcher msgDispatcher;

    public static void main(String[] args) {
        SpringApplication.run(GobangServerApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        msgDispatcher.init();
    }

    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        log.warn("server close!!!");
    }
}
